import router from './router'
import store from './store'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css' // Progress 进度条样式


router.beforeEach((to, from, next) => {
    if(!sessionStorage.token&&to.fullPath!="/login"){
      next("/login")
    }
    //如果没有拉取用户信息
    if(store.getters.user==null){
      store.dispatch('GetUserInfo').then(routers => {
        let route = sessionStorage.currentGroup?JSON.parse(sessionStorage.currentGroup):routers[0];
        store.dispatch('switchRoutes',route);
        router.addRoutes(store.getters.addRouters)
      });
    }
    next();
})

router.afterEach(() => {
  NProgress.done() // 结束Progress
})
